package com.ingesup.controllers
{
	import com.ingesup.models.AppModel;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import org.swizframework.utils.services.ServiceHelper;
	
	public class EmailController
	{
		
		[Inject]
		public var serviceHelper:ServiceHelper;
		
		public var emailSrv:RemoteObject;
		
		public function EmailController()
		{
		}
		
		[EventHandler (event="com.ingesup.events.EmailEvent.SEND", properties="liste")]
		public function send (liste:ArrayCollection):void 
		{
			if (AppModel.lettreCourante && liste.length > 0) 
			{
				serviceHelper.executeServiceCall(emailSrv.envoyerEmail(liste, AppModel.lettreCourante),
					
					function handleGetAllResult(event:ResultEvent):void
					{
						Alert.show("Message envoyé", "Information");
					},
					
					function handleGetAllFault(event:FaultEvent):void 
					{
						Alert.show("Erreur lors de l'envoie du message", "Information");
					}
				);
			}
		}
	}
}